package com.yzc.service.impl;

import com.yzc.Details.SecurityUser;
import com.yzc.mapper.UserMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {

    private final UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SecurityUser securityUser = userMapper.selectByUsername(username);
        log.error("securityUser:{}",securityUser);
        if (securityUser == null) {
            throw new UsernameNotFoundException("用户不存在");
        }
        return securityUser; // 无需手动设置权限，getAuthorities() 会自动处理
    }
}